<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <h3 id="pppp"></h3>
    <script>
      //上次提到不能向现有对象一样给构造函数添加新属性 ↓
      //但是可以使用对象原型
      function User(fname, lname, age, loc) {
        this.firstName = fname;
        this.lastName = lname;
        this.age = age;
        this.location = loc;
      }
      var Seagull = new User("Seagull", "Anna", 22, "New Delhi");
      //prototype可以向构造函数添加属性和方法
      User.prototype.weapon = "Sword";

      User.prototype.fullName = function () {
        return this.firstName + " " + this.lastName;
      };

      for (let p in Seagull) {
        document.write(Seagull[p] + "<br>");
      }

      document.getElementById("pppp").innerHTML = Seagull.fullName();
    </script>
  </body>
</html>
